home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MA3.1.1 & CW4.5 / Modifications / *OR* replace these files / UMacAppUtilities.h < prev    next >
Encoding:
Text File  |  1994-09-17  |  15.0 KB  |  565 lines  |  [TEXT/MPS ]

  1. /*
  2. *    This file has been changed from the original MacApp 3.1.1
  3. *    to support the metrowerks CodeWarrior compilers C/C++ 1.1.1.
  4. *    These changes are known *not* to work with earlier versions
  5. *    of CodeWarrior.  Every attempt though has been made to to keep 
  6. *    this file compatible with other development environments.
  7. *
  8. *    Mark Anderson
  9. *    metrowerks
  10. *    9/16/94
  11. *
  12. */
  13.  
  14. // UMacAppUtilities.h
  15. // Copyright © 1984-1994 by Apple Computer Inc. All rights reserved.
  16. //----------------------------------------------------------------------------------------
  17.  
  18. #ifndef __UMACAPPUTILITIES__
  19. #define __UMACAPPUTILITIES__
  20.  
  21. #ifndef __PASCALSTRING__
  22. #include <PascalString.h>
  23. #endif
  24.  
  25. #ifndef __TOOLBOX__
  26. #include "Toolbox.h"
  27. #endif
  28.  
  29. #ifndef __UGEOMETRY__
  30. #include <UGeometry.h>
  31. #endif
  32.  
  33. #ifndef __TEXTEDIT__
  34. #include <TextEdit.h>
  35. #endif
  36.  
  37. #ifndef __UITERATOR__
  38. #include <UIterator.h>
  39. #endif
  40.  
  41. #ifndef __EDITIONS__
  42. #include <Editions.h>
  43. #endif
  44.  
  45. #ifndef __NOTIFICATION__
  46. #include <Notification.h>
  47. #endif
  48.  
  49. #ifndef __APPLEEVENTS__
  50. #include <AppleEvents.h>
  51. #endif
  52.  
  53. #ifndef __MACAPPTYPES__
  54. #include <MacAppTypes.h>
  55. #endif
  56.  
  57. //----------------------------------------------------------------------------------------
  58. // Global constants declarations. Build options.
  59. //----------------------------------------------------------------------------------------
  60.  
  61. extern const char* kCopyright;
  62.  
  63. // constants passed in as flags to MATextBox()
  64. enum { kDontPreferOutline, kPreferOutline };
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // Some useful struct(s)
  68. //----------------------------------------------------------------------------------------
  69.  
  70. struct MATextStyle {
  71.     Style tsFace;                    // character Style
  72.     char filler;                     // tsFace is unpacked byte
  73.     short tsSize;                    // size in CPoint
  74.     CRGBColor tsColor;                // absolute (RGB) color
  75.     CStr255 tsFont;                  // font (family) number
  76. };
  77.  
  78. typedef MATextStyle *MATextStylePtr, **MATextStyleHandle;
  79.  
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // Global variable declarations.
  83. //----------------------------------------------------------------------------------------
  84.  
  85. extern short gApplicationRefNum;
  86.  
  87. extern Configuration gConfiguration;
  88.  
  89. extern CStr255 gBoolString[2];
  90.  
  91. extern Boolean gToolBoxInitialized;
  92.  
  93. extern Boolean gUDialogInitialized;
  94.  
  95. extern Boolean gUGridViewInitialized;
  96.  
  97. extern Boolean gUPrintingInitialized;
  98.  
  99. extern Boolean gUTEViewInitialized;
  100.  
  101. extern Boolean gUMemoryInitialized;
  102.  
  103. extern Ptr gStrippedAddress;
  104.  
  105. extern TEHandle gMATextBoxTE;
  106.  
  107. extern WordBreakUPP gTEDefaultWordBreak;
  108.  
  109. extern VHSelect gOrthogonal[2];
  110.  
  111. extern CRect gZeroRect;
  112.  
  113. extern CPoint gZeroPt;
  114.  
  115. extern VPoint gZeroVPt;
  116.  
  117. extern VRect gZeroVRect;
  118.  
  119. extern CStr255 gEmptyString;
  120.  
  121. extern CRGBColor gRGBBlack;
  122.  
  123. extern CRGBColor gRGBWhite;
  124.  
  125. extern CRGBColor gRGBRed;
  126.  
  127. extern CRGBColor gRGBGreen;
  128.  
  129. extern CRGBColor gRGBBlue;
  130.  
  131. //------------------------------------------------------------------------------------
  132. // CWhileOutlinePreferred: A simple class for setting/restoring outline preferred.
  133. //------------------------------------------------------------------------------------
  134.  
  135. class CWhileOutlinePreferred
  136. {
  137.     Boolean fPreferOutline;
  138.     Boolean fOutlinePreferredChanged;
  139.  
  140. public:
  141.     // Constructor/destructor
  142.     CWhileOutlinePreferred(Boolean preferOutline);
  143.     ~CWhileOutlinePreferred();
  144. };
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // CStringListRsrc: A simple class for managing and accessing strings in STR# resources.
  148. //
  149. // Limitations: this class has no notion of which resource file to be used for accessing
  150. // the strings from the CString list resource.  This could be added as an enhancement.
  151. //----------------------------------------------------------------------------------------
  152.  
  153. class CStringListRsrc {
  154.  
  155. protected:
  156.     ResNumber    fStrListID;                    // The ID of the STR# rsrc.
  157.     
  158.     CStr255        fStrListRsrcName;            // The name of the STR# rsrc, this is
  159.                                             // only used when adding the STR# rsrc.
  160.  
  161. public:
  162.     //----------------------------------------------------------------------------------------
  163.     // class-scoped constants
  164.     //----------------------------------------------------------------------------------------
  165.     enum { kDontAddString, kAddString };
  166.  
  167.     //----------------------------------------------------------------------------------------
  168.     // constructors
  169.     //----------------------------------------------------------------------------------------
  170.     CStringListRsrc(short strListID, const CStr255& strListRsrcName) :
  171.             fStrListID(strListID),
  172.             fStrListRsrcName(strListRsrcName)
  173.             {}
  174.         // inline constructor
  175.  
  176.     CStringListRsrc(short strListID) :
  177.             fStrListID(strListID)
  178.             { fStrListRsrcName = gEmptyString; }
  179.         // inline constructor
  180.  
  181.     //----------------------------------------------------------------------------------------
  182.     // accessors
  183.     //----------------------------------------------------------------------------------------
  184.     short AppendString(const CStr255& theString);
  185.         // append theString to the STR# resource whose id is fStrListID and return its index
  186.     
  187.     void ClearAll();
  188.         // clears all strings in the STR# resource
  189.  
  190.     short CountStrings() const;
  191.         // returns the number of strings in the STR# resource whose id is fStrListID
  192.  
  193.     short FindString(const CStr255& theString, Boolean addString = kDontAddString);
  194.         // find theString in the STR# resource whose id is fStrListID and return its index
  195.         // if theString is not found in the STR# resource, add it if addString is kAddString
  196.     
  197.     void GetListName(CStr255& itsName);
  198.         //    Returns the name of the STR# list either from its field or if that is empty
  199.         //    from the actual resource
  200.  
  201.     void GetString(short index, CStr255& theString) const;
  202.         // return in theString the "index" CString in the STR# resource whose id is fStrListID
  203.  
  204.     void RemoveAt(short index);
  205.         // removes the CString at the specified index.
  206.     
  207.     void ReplaceAt(const CStr255& theString, short index);
  208.         // replace the CString at "index" with "theString"
  209. };
  210.  
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // CWMgrIterator: A simple iterator for window lists.
  214. //----------------------------------------------------------------------------------------
  215.  
  216. class CWMgrIterator : public CIterator
  217. {
  218. private:
  219.     WindowPtr fCurrentWindow;
  220.     
  221. protected:
  222.     Boolean fIterateForward;
  223.  
  224. public:
  225.     CWMgrIterator();
  226.     CWMgrIterator(Boolean itsForward);
  227.  
  228.     virtual Boolean More();                    // override
  229.         // Returns true if there are more elements to iterate over
  230.  
  231.     virtual void Reset();                    // override
  232.         // Resets the iterator to begin again
  233.  
  234.     inline WindowPtr CurrentWMgrWindow();
  235.         // returns the current window
  236.  
  237.     inline WindowPtr FirstWMgrWindow();
  238.         // Resets the iterator to begin again and returns the first window in the window list
  239.  
  240.     inline WindowPtr NextWMgrWindow();
  241.         // increments and then returns the window in the window list
  242.  
  243. protected:
  244.     virtual void Advance();                    // override
  245.         // Advances the iteration
  246.  
  247.     WindowPtr NextWindow(WindowPtr aWindow);
  248.         // returns the next window in the window list, excluding gWorkPort
  249.         
  250.     WindowPtr PreviousWindow(WindowPtr aWindow);
  251.         // returns the previous window in the window list, excluding gWorkPort
  252.  
  253.     WindowPtr FirstWindow();
  254.         // returns the first window in the window list, excluding gWorkPort
  255.         
  256.     WindowPtr LastWindow();
  257.         // returns the last window in the window list, excluding gWorkPort
  258.  
  259. };
  260.  
  261.  
  262. //----------------------------------------------------------------------------------------
  263. // CWMgrIterator inline method definitions.
  264. //----------------------------------------------------------------------------------------
  265.  
  266. inline WindowPtr CWMgrIterator::CurrentWMgrWindow()
  267. {
  268.     return fCurrentWindow;                        // Always return the current window
  269. }
  270.  
  271. inline WindowPtr CWMgrIterator::FirstWMgrWindow()
  272. {
  273.     this->Reset();
  274.     return fCurrentWindow;                        // Always return the first window
  275. }
  276.  
  277. inline WindowPtr CWMgrIterator::NextWMgrWindow()
  278. {
  279.     this->Advance();
  280.     return fCurrentWindow;
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. // Global assembly inline function definitions.
  285. //----------------------------------------------------------------------------------------
  286.  
  287. #if !qPowerPC
  288. long GetParmBlockPtr() = { 0x2008 };            // MOVE.L A0,D0
  289.                                                 // Return the value of register A0.
  290.                                                 // Useful for getting the pointer
  291.                                                 // to the parameter block from a
  292.                                                 // VBL task or a completion routine.
  293. #endif
  294.  
  295. #if !qPowerPC
  296. long GetA5() = { 0x200D };                        // MOVE.L A5,D0
  297.                                                 // Return the value of register A5.
  298.                                                 // Useful for getting the immediate
  299.                                                 // value of A5 which is not always
  300.                                                 // the same as CurrentA5.  Generally
  301.                                                 // a pointer to the program's global
  302.                                                 // area and jump table.    
  303.  
  304. #if qDebug
  305. #ifdef __MWERKS__
  306.     #pragma pointers_in_D0
  307. #endif
  308. Ptr GetCurStackFramePtr() = { 0x200E };            // MOVE.L A6,D0
  309.                                                 // Return the value of register A6.
  310.                                                 // Usually a pointer to the local
  311.                                                 // stack frame.  Most often used to
  312.                                                 // find out the caller's name when
  313.                                                 // invoking a debugging routine.
  314.     
  315. Ptr GetCurStackTop() = { 0x200F };                // MOVE.L A7,D0
  316.                                                 // Return the value of register A7.
  317.                                                 // Usually the top of the stack.
  318.                                                 // Useful for stack sniffing (not
  319.                                                 // a crime).
  320. #ifdef __MWERKS__
  321.     #pragma pointers_in_A0
  322. #endif
  323. #endif
  324. #endif
  325.  
  326. //----------------------------------------------------------------------------------------
  327. // Global function declarations that needs to always be compiled for 68000.
  328. //----------------------------------------------------------------------------------------
  329.  
  330. void BlockSet(Ptr destPtr,
  331.               long byteCount,
  332.               unsigned char setVal);
  333.  
  334. void CenterRectOnScreen(CRect& aRect,
  335.                         Boolean horizontally,
  336.                         Boolean vertically,
  337.                         Boolean forDialog);
  338.  
  339. void ConcatNumber(const CStr255& aString,
  340.                   long aNumber,
  341.                   CStr255& theResult);
  342.  
  343. TrapType GetTrapType(short theTrap);
  344.  
  345. void PullApplicationToFront();
  346.  
  347. void SetRGBColor(CRGBColor& RGB,
  348.                  short aRed,
  349.                  short aGreen,
  350.                  short aBlue);
  351.  
  352. Boolean TrapExists(short theTrap);
  353.  
  354. OSErr MAInteractWithUser(long timeOutInTicks, NMRecPtr nmReqPtr, AEIdleUPP idleProc);
  355.     // A wrapper for AEInteractWithUser.  Called before displaying a modal dialog
  356.     // or alert.  Used as our bottleneck for the Notification Manager.
  357.  
  358. //----------------------------------------------------------------------------------------
  359. // Global function declarations
  360. //----------------------------------------------------------------------------------------
  361.  
  362. Boolean CompareMultiByteChars(const CStr31& first,
  363.                               const CStr31& second,
  364.                               Boolean caseSens);
  365.     // Special case single byte characters and allow case insensitive comparisons
  366.  
  367. short CompareStrings(const CStr255& first,
  368.                      const CStr255& second);
  369.  
  370. void CopyStr255(const CStr255& fmStr,
  371.                 Ptr toAddr);
  372.  
  373. WindowPtr FindWindowBefore(WindowPtr theWindow);
  374.  
  375. void DefaultSize(short& theSize);
  376.  
  377. Handle DisposeIfHandle(Handle aHandle);
  378.  
  379. PicHandle DisposeIfPicHandle(PicHandle aPicHandle);
  380.  
  381. Ptr DisposeIfPtr(Ptr aPtr);
  382.  
  383. RgnHandle DisposeIfRgnHandle(RgnHandle aRgnHandle);
  384.  
  385. SectionHandle DisposeIfSectionHandle(SectionHandle aSectionHandle);
  386.  
  387. UniversalProcPtr DisposeIfRoutineDescriptor(UniversalProcPtr aUniversalProcPtr);
  388.  
  389. Boolean EqualBlocks(Ptr first,
  390.                     Ptr second,
  391.                     short theSize);
  392.  
  393. short GetActualJustification(short justification);
  394.  
  395. void GetDeskTopRegion(RgnHandle deskTopRgn);
  396.  
  397. short GetFontNum(const CStr255& fontName);
  398.  
  399. void GetIfColor(CRGBColor& aColor);
  400.  
  401. void GetIfBkColor(CRGBColor& aColor);
  402.  
  403. void GetPortTextStyle(TextStyle& theTextStyle);
  404.  
  405. void MAGetTextStyle(ResNumber rsrcID, TextStyle& theTextStyle);
  406. // Given the rsrcID of a 'TxSt' resource, this function creates and
  407. // returns in theTextStyle the corresponding TextStyle record.
  408.  
  409. void GetPortFontInfo(short fontNum, CStr255& fontName, short& fontSize);
  410.  
  411. Boolean IsColorPort(GrafPtr port);
  412.  
  413. Boolean IsAResource(Handle h);
  414.  
  415. Boolean IsHandle(Handle h);
  416.  
  417. Boolean IsHandleLocked(Handle h);
  418.  
  419. #if qDebug
  420.     Boolean IsHandlePurged(Handle h);
  421. #else
  422.     inline Boolean IsHandlePurged(Handle h)
  423.     {
  424.         return (!*h);
  425.     }
  426. #endif
  427.  
  428. short GetWindowVariant(WindowPtr theWindow);
  429.  
  430. short LengthRect(const CRect& r, VHSelect vhs);
  431.  
  432. SignedByte LockHandleHigh(Handle h);
  433.  
  434. VHSelect LongerSide(CRect& r);
  435.  
  436. VHSelect LongerVSide(VRect& r);
  437.  
  438. void LIntToHex(long decNumber, CStr31& hexNumber, short noOfDigits);
  439.  
  440. short MAGetFontInfo(FontInfo& theFontInfo);
  441.  
  442. short MAUseResFile(short refNum);
  443.  
  444. void MATextBox(Ptr text,
  445.                long itsLength,
  446.                const CRect& box,
  447.                short itsJust,
  448.                Boolean autoWrap,
  449.                ProcPtr wordBreak,
  450.                Boolean eraseFirst,
  451.                Boolean spaceForCaret,
  452.                Boolean preferOutline = kDontPreferOutline);
  453.  
  454. void MADrawString(const CStr255& s,
  455.                   const CRect& box,
  456.                   short justification,
  457.                   Boolean preferOutline = kDontPreferOutline);
  458.  
  459. inline long Max(long a, long b)
  460. {
  461.     return a > b ? a : b;
  462. }
  463.  
  464. inline long Min(long a, long b)
  465. {
  466.     return a < b ? a : b;
  467. }
  468.  
  469. // Returns the bounded minimum and maximum 
  470. long MinMax(long MinVal, long expression, long MaxVal);
  471.  
  472. void NumberToHex(long theNumber,
  473.                  CStr255& hexString,
  474.                  short hexDigits);
  475.  
  476. Boolean IsCommandKeyDown();
  477.  
  478. Boolean IsControlKeyDown();
  479.  
  480. Boolean IsOptionKeyDown();
  481.  
  482. Boolean IsShiftKeyDown();
  483.  
  484. long PinOnRect(const CRect& theRect, CPoint thePt);
  485.  
  486. void PinOnVRect(const VRect& theRect, const VPoint& thePt, VPoint& thePin);
  487.  
  488. long StripLong(void* address);
  489.  
  490. void PointerToHex(long theNumber, CStr31& hexString, short hexDigits);
  491.  
  492. Boolean RectsNest(const CRect& outer, const CRect& inner);
  493.  
  494. Boolean VRectsNest(const VRect& outer, const VRect& inner);
  495.  
  496. long RoundUp(long aNumber, short aModulus);
  497.  
  498. short SetKeyScript(short newKeyScript);
  499.  
  500. void SetIfColor(const CRGBColor& aColor);
  501.  
  502. void SetIfBkColor(const CRGBColor& aColor);
  503.  
  504. void SetPortTextStyle(const TextStyle& theTextStyle);
  505.  
  506. void SetTextStyle(TextStyle& theTextStyle,
  507.                   short theFont,
  508.                   /* Style */
  509.                   short theStyle,
  510.                   short theSize,
  511.                   const CRGBColor& theColor);
  512.  
  513. short UprChar(short ch);
  514.  
  515. void UprStr255(CStr255& s);
  516.  
  517. void UprMAName(MAName& s);
  518.  
  519. short LowerChar(short ch);
  520.  
  521. void LowerStr255(CStr255& s);
  522.  
  523. void UseSelectionColor();
  524.  
  525. void UseROMMap(Boolean resLoad);
  526.  
  527. long NumBlocks(long numBytes, long blkSize);
  528.  
  529. Boolean CanReadLn();
  530.  
  531. Boolean CanWriteLn();
  532.  
  533. Boolean VerboseIsHandle(Handle h);
  534.  
  535. void WriteHandleContents(Handle theHandle);
  536.  
  537. void WrLblHandleContents(const CStr255& aLabel, Handle theHandle);
  538.                                 
  539. void WritePtr(long val);
  540.  
  541. void WrLblPtr(const CStr255& aLabel, long val);
  542.  
  543. void WriteBoolean(Boolean b);
  544.  
  545. void WrLblBoolean(const CStr255& aLabel, Boolean b);
  546.  
  547. void WriteSig(IDType theID);
  548.  
  549. void WrLblSig(const CStr255& theLabel, IDType theID);
  550.  
  551. void WriteHexInt(short theInt);
  552.  
  553. void WrLblHexInt(const CStr255& theLabel, short theInt);
  554.  
  555. void WriteHexLongint(long theLongint);
  556.  
  557. void WrLblHexLongint(const CStr255& theLabel, long theLongint);
  558.  
  559. void XorPat(const Pattern& patA, const Pattern& patB, Pattern& toPat);
  560. void CopyPat(const Pattern& pat, Pattern& toPat);
  561. void RotatePat(Pattern& aPattern);
  562. #endif
  563.  
  564.  
  565.